<?php
namespace Admin\Controller;
use Think\Controller;
class ClubController extends Controller
{
    public function index()
    {
        $this->display();
       
    }

    /*俱乐部信息*/
    public function clubintro(){
        $club = M('club');
        $clublist = $club->order("clubid desc")->select();


        $this->assign('club',$clublist);
        $this->display();
    }

/*俱乐部信息(超级管理员查看)*/
    public function Sclublist(){
        $club = M('club');
        $Sclublist = $club->order("clubid desc")->select();

        

        $this->assign('Sclublist',$Sclublist);
        $this->display();
    }

  
/*修改俱乐部信息*/
public function editintro(){
        $clubid=$_GET['clubid'];
        $clubModel=M('club');
        $club= $clubModel->where("clubid=$clubid")->select();

        //dump($lost);
        $this->club=$club;         //name属性对应的值 $this->对应值=$find;
        $this->display();
    }
 
  public function updateclub(){

            $data=$_POST;
            $file=$_FILES;
           
            $clubid=$data['clubid'];
                   
            $clubModel = M('club'); // 实例化Club模型
            // 要修改的数据对象属性赋值
         
        if ($file['clubpic']['size']==0) {
            //没有修改头像
            $result=$clubModel->where("clubid=$clubid")->save($data);
                    
  
        }else{
            //修改头像
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize  = 3145728 ;// 设置附件上传大小
            $upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath  =  './';
            $upload->savePath =  'Public/Uploads/photo/';// 设置附件上传目录
            $upload->autoSub = false;
            $upload->saveName = date("YmdHis").rand(100,999);//定义名字
            $info = $upload->upload();
    
            if(!$info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
             }else{// 上传成功 获取上传文件信息
                 //保存表单数据 包括附件数据
                


                $data['clubpic']= $info['clubpic']['savename']; 

                $result=$clubModel->where("clubid=$clubid")->save($data);
                    if ($data['oldpic']!='nopic.jpg') {
                    $oldpicPath='Public/Uploads/photo/'.$data['oldpic'];
                    unlink($oldpicPath);
                        }
                    }
            }
           
           if($result){
                $this->success('修改成功！','../Club/clubintro');
                }
               else{
                   $this->error('修改失败！');
                   }
    }  

     public function Upload(){
                //上传头像
              $upload = new \Think\Upload();// 实例化上传类
              $upload->maxSize  = 3145728 ;// 设置附件上传大小
              $upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
              $upload->rootPath  =  './';
              $upload->savePath =  'Public/Uploads/photo/';// 设置附件上传目录
              $upload->autoSub = false;
              $upload->saveName = date("YmdHis").rand(100,999);//定义名字
               // 上传单个文件 
              $info = $upload->upload();                    
                  if(!$info) {// 上传错误提示错误信息
                      $this->error($upload->getError());
                    }else{// 上传成功 获取上传文件信息
                return $info;
                         }
    } 
 }
